package com.maskota;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.SystemClock;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

public class Alertas extends Activity {
    private PendingIntent mAlarmSender;
    private PendingIntent mAlarmSender1;
    private PendingIntent mAlarmSender2;
    private PendingIntent mAlarmSender3;
    private PendingIntent mAlarmSender4;
    TextView alertas;
    
    @Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create an IntentSender that will launch our service, to be scheduled
        // with the alarm manager.
	
        setContentView(R.layout.alarm_service);
        
    	Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/vagroundedbold.ttf");
		alertas = (TextView) findViewById(R.id.alertas);
		alertas.setTypeface(tf);
        

        //Check para el alimento
        CheckBox chek = (CheckBox) findViewById(R.id.actdesac);
        CheckBox chekpaseos = (CheckBox) findViewById(R.id.paseos);
        CheckBox chekaseos = (CheckBox) findViewById(R.id.aseos);
        CheckBox chekveterinario = (CheckBox) findViewById(R.id.veterinario);
        CheckBox chekcompralimento = (CheckBox) findViewById(R.id.comprar);

        chek.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				  if(((CheckBox) v).isChecked()==true){
		        	  long firstTime = SystemClock.elapsedRealtime();

		        	    mAlarmSender = PendingIntent.getService(Alertas.this,
		                        0, new Intent(Alertas.this, AlarmService_Service.class), 0);
		        	  
		              // Schedule the alarm!
		              AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		              am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
		                              firstTime, 30*1000, mAlarmSender);

		              // Tell the user about what we did.
		              Toast.makeText(Alertas.this, R.string.repeating_scheduled,
		                      Toast.LENGTH_LONG).show();
		        	
		        }else{
		        	
		            // And cancel the alarm.
		            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		            am.cancel(mAlarmSender);

		            // Tell the user about what we did.
		            Toast.makeText(Alertas.this, R.string.repeating_unscheduled,
		                    Toast.LENGTH_LONG).show();
		        }				
			}
		});
        
        chekpaseos.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				  if(((CheckBox) v).isChecked()==true){
		        	  long firstTime = SystemClock.elapsedRealtime();
		        	  
		        	    mAlarmSender1 = PendingIntent.getService(Alertas.this,
		                        0, new Intent(Alertas.this, AlarmService_Paseo.class), 0);

		              // Schedule the alarm!
		              AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		              am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
		                              firstTime, 500*1000, mAlarmSender1);

		              // Tell the user about what we did.
		              Toast.makeText(Alertas.this, R.string.repeating_scheduled,
		                      Toast.LENGTH_LONG).show();
		        	
		        }else{
		        	
		            // And cancel the alarm.
		            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		            am.cancel(mAlarmSender1);

		            // Tell the user about what we did.
		            Toast.makeText(Alertas.this, R.string.repeating_unscheduled,
		                    Toast.LENGTH_LONG).show();
		        }	
				
			}
		});
        
        chekaseos.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				  if(((CheckBox) v).isChecked()==true){
		        	  long firstTime = SystemClock.elapsedRealtime();
		        	  
		        	    mAlarmSender2 = PendingIntent.getService(Alertas.this,
		                        0, new Intent(Alertas.this, AlarmService_asear.class), 0);

		              // Schedule the alarm!
		              AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		              am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
		                              firstTime, 300*1000, mAlarmSender2);

		              // Tell the user about what we did.
		              Toast.makeText(Alertas.this, R.string.repeating_scheduled,
		                      Toast.LENGTH_LONG).show();
		        	
		        }else{
		        	
		            // And cancel the alarm.
		            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		            am.cancel(mAlarmSender2);

		            // Tell the user about what we did.
		            Toast.makeText(Alertas.this, R.string.repeating_unscheduled,
		                    Toast.LENGTH_LONG).show();
		        }	
				
			}
		});
        
        chekveterinario.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				  if(((CheckBox) v).isChecked()==true){
		        	  long firstTime = SystemClock.elapsedRealtime();
		        	  
		        	    mAlarmSender3 = PendingIntent.getService(Alertas.this,
		                        0, new Intent(Alertas.this, AlarmService_Veterinario.class), 0);

		              // Schedule the alarm!
		              AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		              am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
		                              firstTime, 80*1000, mAlarmSender3);

		              // Tell the user about what we did.
		              Toast.makeText(Alertas.this, R.string.repeating_scheduled,
		                      Toast.LENGTH_LONG).show();
		        	
		        }else{
		        	
		            // And cancel the alarm.
		            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		            am.cancel(mAlarmSender3);

		            // Tell the user about what we did.
		            Toast.makeText(Alertas.this, R.string.repeating_unscheduled,
		                    Toast.LENGTH_LONG).show();
		        }					
			}
		});
        
        chekcompralimento.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				  if(((CheckBox) v).isChecked()==true){
		        	  long firstTime = SystemClock.elapsedRealtime();
		        	  
		        	    mAlarmSender4 = PendingIntent.getService(Alertas.this,
		                        0, new Intent(Alertas.this, AlarmService_Comprar.class), 0);

		              // Schedule the alarm!
		              AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		              am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
		                              firstTime, 100*1000, mAlarmSender4);

		              // Tell the user about what we did.
		              Toast.makeText(Alertas.this, R.string.repeating_scheduled,
		                      Toast.LENGTH_LONG).show();
		        	
		        }else{
		        	
		            // And cancel the alarm.
		            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		            am.cancel(mAlarmSender4);

		            // Tell the user about what we did.
		            Toast.makeText(Alertas.this, R.string.repeating_unscheduled,
		                    Toast.LENGTH_LONG).show();
		        }					
			}
		});
        
    }
}
